#ifndef __CONVERT_H__
#define __CONVERT_H__
#include <stdint.h>
#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief convert char to hex
 */
extern uint8_t convert_char2hex(int ch);

/**
 * @brief convert hex to char
 */
extern int convert_hex2char(uint8_t hex);

/**
 * @brief convert hex to decimal
 */
extern uint32_t convert_hex2dec(const char *hex);

/**
 * @brief convert string to hex
 */
extern int convert_str2hex(uint8_t hex[], size_t len, const char *str);

/**
 * @brief convert hex to string
 */
extern int convert_hex2str(char *str, size_t size, const uint8_t hex[], size_t len);

/**
 * @brief Returns the string cp points to into unsigned long integer data.
 * 
 * @param cp [in]: Points to the starting address of the string to be converted;
 * @param endp [out]: Returns the last character of the string if needed;
 * @param base [in]: The decimal type of the cp string.
 * @return unsigned long integer data
 */
extern unsigned long int convert_str2ul(const char *cp,char **endp,unsigned int base);

/**
 * @brief Returns the string cp points to into long integer data.
 * 
 * @param cp [in]: Points to the starting address of the string to be converted;
 * @param endp [out]: Returns the last character of the string if needed;
 * @param base [in]: The decimal type of the cp string.
 * @return long integer data
 */
extern long int convert_str2l(const char *cp,char **endp,unsigned int base);

/**
 * @brief Returns the string cp points to into unsigned long long integer data.
 * 
 * @param cp [in]: Points to the starting address of the string to be converted;
 * @param endp [out]: Returns the last character of the string if needed;
 * @param base [in]: The decimal type of the cp string.
 * @return unsigned long long integer data
 */
extern unsigned long long int convert_str2ull (const char *cp, char **endp, unsigned int base);

/**
 * @brief Returns the string cp points to into long long integer data.
 * 
 * @param cp [in]: Points to the starting address of the string to be converted;
 * @param endp [out]: Returns the last character of the string if needed;
 * @param base [in]: The decimal type of the cp string.
 * @return long long integer data
 */
extern long long int convert_str2ll(const char *cp,char **endp,unsigned int base);

#ifdef __cplusplus
}
#endif

#endif // __CONVERT_H__
